import { getSetting } from "@/api/setting";
import { setTitle } from "@/utils";

export default {
	namespaced: true,
	state: {
		datas: null,
	},
	mutations: {
		setDatas(state, payout) {
			state.datas = payout;
		},
	},
	actions: {
		async fetchSetting(ctx) {
			const resp = await getSetting();
			ctx.commit("setDatas", resp);
			//判断是否有网页小图标
			if (resp.favicon) {
				let link = document.querySelector("link[rel='shortcut icon']");
				if (link) {
					return;
				}
				link = document.createElement("link");
				link.rel = "shortcut icon";
				link.href = resp.favicon;
				document.querySelector("head").appendChild(link);
			}
			//判断是否有网站标题
			if (resp.siteTitle) {
				setTitle.setsiteTitle(resp.siteTitle);
			}
		},
	},
};
